package com.taotao.portal.service.ipml;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.Item;
import com.taotao.common.pojo.SearchResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.HttpClientUtil;
import com.taotao.portal.service.ISearchService;

@Service
public class SearchServiceIpml implements ISearchService {

	@Value("${SEARCH_BASE_URL}")
	private String SEARCH_BASE_URL;

	@Override
	public TaotaoResult Search(String queryString, Integer page, Integer rows) {
		// TODO Auto-generated method stub
		Map<String, String> param = new HashMap<String, String>();
		param.put("q", queryString);
		param.put("page", page + "");
		param.put("rows", rows + "");

		String jsonStr = HttpClientUtil.doGet(SEARCH_BASE_URL, param);
		TaotaoResult result = TaotaoResult.formatToPojo(jsonStr,
				SearchResult.class);
		if (200 == result.getStatus()) {
			return result;
		}
		return null;
	}
}
